#!/bin/sh

if [ -x sbin/ldconfig ]; then
  sbin/ldconfig -r .
fi

config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then # toss the redundant copy
    rm $NEW
  fi
}
config etc/nscd.conf.new

( cd usr/share/zoneinfo ; rm -rf localtime )
( cd usr/share/zoneinfo ; ln -sf /etc/localtime localtime )
( cd usr/share/zoneinfo ; rm -rf timeconfig )
( cd usr/share/zoneinfo ; ln -sf /usr/sbin/timeconfig timeconfig )

if [ -x sbin/ldconfig ]; then
  sbin/ldconfig -r .
else
  ( cd lib ; rm -rf libnss_nis.so.2 )
  ( cd lib ; ln -sf libnss_nis-2.6.1.so libnss_nis.so.2 )
  ( cd lib ; rm -rf libm.so.6 )
  ( cd lib ; ln -sf libm-2.6.1.so libm.so.6 )
  ( cd lib ; rm -rf libnss_files.so.2 )
  ( cd lib ; ln -sf libnss_files-2.6.1.so libnss_files.so.2 )
  ( cd lib ; rm -rf libresolv.so.2 )
  ( cd lib ; ln -sf libresolv-2.6.1.so libresolv.so.2 )
  ( cd lib ; rm -rf libnsl.so.1 )
  ( cd lib ; ln -sf libnsl-2.6.1.so libnsl.so.1 )
  ( cd lib ; rm -rf libutil.so.1 )
  ( cd lib ; ln -sf libutil-2.6.1.so libutil.so.1 )
  ( cd lib ; rm -rf libnss_compat.so.2 )
  ( cd lib ; ln -sf libnss_compat-2.6.1.so libnss_compat.so.2 )
  ( cd lib ; rm -rf libthread_db.so.1 )
  ( cd lib ; ln -sf libthread_db-1.0.so libthread_db.so.1 )
  ( cd lib ; rm -rf libnss_hesiod.so.2 )
  ( cd lib ; ln -sf libnss_hesiod-2.6.1.so libnss_hesiod.so.2 )
  ( cd lib ; rm -rf libanl.so.1 )
  ( cd lib ; ln -sf libanl-2.6.1.so libanl.so.1 )
  ( cd lib ; rm -rf libcrypt.so.1 )
  ( cd lib ; ln -sf libcrypt-2.6.1.so libcrypt.so.1 )
  ( cd lib ; rm -rf libBrokenLocale.so.1 )
  ( cd lib ; ln -sf libBrokenLocale-2.6.1.so libBrokenLocale.so.1 )
  ( cd lib ; rm -rf ld-linux.so.2 )
  ( cd lib ; ln -sf ld-2.6.1.so ld-linux.so.2 )
  ( cd lib ; rm -rf libdl.so.2 )
  ( cd lib ; ln -sf libdl-2.6.1.so libdl.so.2 )
  ( cd lib ; rm -rf libnss_dns.so.2 )
  ( cd lib ; ln -sf libnss_dns-2.6.1.so libnss_dns.so.2 )
  ( cd lib ; rm -rf libpthread.so.0 )
  ( cd lib ; ln -sf libpthread-2.6.1.so libpthread.so.0 )
  ( cd lib ; rm -rf libnss_nisplus.so.2 )
  ( cd lib ; ln -sf libnss_nisplus-2.6.1.so libnss_nisplus.so.2 )
  ( cd lib ; rm -rf libc.so.6 )
  ( cd lib ; ln -sf libc-2.6.1.so libc.so.6 )
  ( cd lib ; rm -rf librt.so.1 )
  ( cd lib ; ln -sf librt-2.6.1.so librt.so.1 )
fi
